import { Component } from "cc";

export class DatabaseMgr {
    private url: string = "http://106.52.15.210:5001/";
    private static _instance: DatabaseMgr | null = null;

    private constructor() {}

    public static get Instance(): DatabaseMgr {
        if (!this._instance) {
            this._instance = new DatabaseMgr();
        }
        return this._instance;
    }

    public async fetchData(): Promise<any> {
        try {
            const response = await fetch(this.url + 'levels');
            if (!response.ok) {
                throw new Error(`Network response was not ok: ${response.statusText}`);
            }
            const data = await response.json();
            console.log('Fetched data:', data);
            return data;
        } catch (error) {
            console.error('Fetch error:', error);
            throw error;
        }
    }
}
